''''''

# Standard
# Related
import lx
# Local


_layerservice = lx.Service('layerservice')
_layerservice_query = _layerservice.query
_layerservice_select = _layerservice.select
_sceneservice = lx.Service('sceneservice')
_sceneservice_query = _sceneservice.query
_sceneservice_select = _sceneservice.select

def get_all_item_ids(item_type=None):
    '''Get all the item id's the active scene.

    @param item_type: Restrict the return id's to only this given item type.
    '''
    if item_type is None:
        item_type = 'item'
    
    items = []
    total_items = _sceneservice_query('%s.N' % item_type)
    # Store the item.id string so that it isn't calculated every iteration.
    item_id_string = '%s.id' % item_type
    for i in range(total_items):
        _sceneservice_select(item_type, str(i))
        items.append(_sceneservice_query(item_id_string))

    if items:
        return items
    else:
        return None

def get_item_name(item_id):
    ''''''

    _sceneservice_select('item.name', item_id)
    return _sceneservice_query('item.name')

def get_item_layer_index(item_id):
    '''Get the layer index, as returned by layerservice's layer.index.'''
    
    _layerservice_select('layer.index', item_id)
    return int(_layerservice_query('layer.index'))

def get_selected_item_ids(item_type=None):
    '''Get the selected item id's the active scene.

    @param item_type: Restrict the return id's to only this given item type.
    '''
    if item_type is None:
        item_type = 'item'
    
    items = []
    total_items = _sceneservice_query('%s.N' % item_type)
    # Store the item.id string so that it isn't calculated every iteration.
    item_id_string = '%s.id' % item_type
    for i in range(total_items):
        _sceneservice_select(item_type, str(i))
        if not not _sceneservice_query('item.isSelected'):
            items.append(_sceneservice_query(item_id_string))

    if items:
        return items
    else:
        return None

